<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <style>
  html, body {
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#container {
  width: 100%;
  height: 100%;
  background: black;
}

#container canvas{
  width: 100%;
  height: 100%;
}
  </style>
</head>
<body>
  <div id="container"></div>
  <script src="https://s4.ssl.qhres.com/!ce414b25/spritejs.min.js"></script>
  <script>
  const img = new Image()
  img.src = ''
  
  const {Scene, Sprite} = spritejs
  const scene = new Scene('#container', {
    viewport: ['auto', 'auto'],
  })
  const layer = scene.layer('fglayer')
  const [width, height] = layer.resolution

  function loadResponsiveImage(img, width) {
    const canvas = document.createElement('canvas')
    canvas.width = width
    canvas.height = img.height
    canvas.getContext('2d').drawImage(img, 0, 0)
    return canvas
  }
  
  const w = width * 0.5
  const sprite = new Sprite({
    anchor: 0.5,
    pos: [w, 100],
    textures: [{image: loadResponsiveImage(img, w)}],
    width: w,
  })

  layer.append(sprite)
  
  img.addEventListener('load', () => {
    sprite.forceUpdate()
  })

  console.log(sprite.attr('size'), img.height, sprite.texturesSize)

  window.addEventListener('resize', (evt) => {
    const [w, h] = scene.viewport
    scene.setResolution(w, h)
    sprite.attr({x: w * 0.5, width: w * 0.5})
    sprite.attr('textures', [{image: loadResponsiveImage(img, w * 0.5)}])
  })
  </script>
</body>
</html>